package org.flexspeedup.blog.admin.views
{
import flash.events.IEventDispatcher;
import flash.events.MouseEvent;

import org.flexspeedup.blog.admin.events.CreateCategoryEvent;
import org.flexspeedup.blog.events.ShowPopUpEvent;
import org.flexspeedup.blog.models.PopUpModel;
import org.flexspeedup.model.IListModel;

import spark.components.Button;
import spark.components.DropDownList;
import spark.components.TextInput;
import spark.components.supportClasses.SkinnableComponent;

[SkinState("normal")]
/**
 * This component allows to edit and select categories
 */
public class CategoryEditor extends SkinnableComponent
{

    //--------------------------------------------------------------------------
    //
    // Constructor
    //
    //--------------------------------------------------------------------------

    /**
     * Creates a new <code>CategoryEditor</code> instance.
     */
    public function CategoryEditor()
    {
        super();
    }
    
    //--------------------------------------------------------------------------
    //
    //  Skin parts
    //
    //--------------------------------------------------------------------------

    //----------------------------------
    //  categoryDropDown
    //----------------------------------
    [SkinPart(required="true")]
    public var categoryDropDown:DropDownList;

    //--------------------------------------------------------------------------
    //
    //  Variables
    //
    //--------------------------------------------------------------------------

    //--------------------------------------------------------------------------
    //
    //  Properties
    //
    //--------------------------------------------------------------------------    

    //----------------------------------
    //  model
    //----------------------------------
    /**
     *  @private
     */    
    private var _model:IListModel;

    //----------------------------------
    //  modelChanged
    //----------------------------------
    /**
     *  @private
     */
    private var modelChanged:Boolean;
    [Bindable]
    /**
     * The model for this component
     */
    public function get model():IListModel
    {
        return _model;
    }
    
    public function set model(value:IListModel):void
    {
        if (value == _model)
            return;
            
        _model = value;
        modelChanged = true;
        invalidateProperties();
    }

    //--------------------------------------------------------------------------
    //
    //  Overridden Methods - UIComponent
    //
    //--------------------------------------------------------------------------

    /**
     *  @private
     */
    override protected function commitProperties():void
    {
        super.commitProperties();
        
        if (modelChanged)
        {
            modelChanged = false;
            if (categoryDropDown)
                categoryDropDown.dataProvider = model.dataProvider;
        }
    }

    /**
     *  @private
     */
    override protected function partAdded(partName:String, instance:Object):void
    {
        switch (instance)
        {
            case (categoryDropDown):
            {
                if (model)
                    categoryDropDown.dataProvider = model.dataProvider;
            }
        }
    }

    //--------------------------------------------------------------------------
    //
    //  Event handlers
    //
    //--------------------------------------------------------------------------

}
}